# Dockerfile (using Aliyun mirrors)

# 步骤 1: 选择一个最小的 Python Alpine 基础镜像
# Step 1: Choose a minimal Python Alpine base image
FROM python:3.12-alpine

# 设置一些有用的标签 (可选)
# Set some useful labels (optional)
LABEL maintainer="Your Name <your.email@example.com>"
LABEL description="Docker image with yt-dlp, aria2c, ffmpeg (using Aliyun mirrors) based on Python Alpine."

# 步骤 2: 配置阿里云 APK 镜像源并安装系统依赖
# Step 2: Configure Aliyun APK mirror and install system dependencies
#   - 使用 sed 命令将官方源替换为阿里云镜像源
#   - Use sed to replace the official repository URL with the Aliyun mirror URL
#   - 更新包列表并安装 aria2c 和 ffmpeg
#   - Update package list and install aria2c and ffmpeg
#   - 使用 --no-cache 选项减少镜像大小
#   - Use --no-cache option to reduce image size
#   - 最后清理 apk 缓存
#   - Clean up apk cache afterwards
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
    apk update && \
    apk add --no-cache \
        aria2 \
        ffmpeg && \
    rm -rf /var/cache/apk/*

# 步骤 3: 使用 pip 安装 yt-dlp，并指定阿里云 PyPI 镜像源
# Step 3: Install yt-dlp using pip, specifying the Aliyun PyPI mirror
#   - 使用 -i 参数指定镜像源地址
#   - Use the -i argument to specify the mirror URL
#   - 使用 --trusted-host 允许 http 或解决潜在的 SSL 问题
#   - Use --trusted-host to allow http or resolve potential SSL issues
#   - 使用 --no-cache-dir 减小镜像大小
#   - Use --no-cache-dir to reduce image size
RUN pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com yt-dlp

# 步骤 4: 创建下载目录
# Step 4: Create the download directory
RUN mkdir /downloads

# 步骤 5: 将下载目录设置为工作目录
# Step 5: Set the download directory as the working directory
WORKDIR /downloads

# 步骤 6: 将下载目录声明为卷 (Volume)
# Step 6: Declare the download directory as a volume
# 这使得将主机目录挂载到容器的 /downloads 更容易，以持久化文件
# This makes it easier to mount a host directory to /downloads in the container for persistence
VOLUME /downloads

# 步骤 7: 设置默认入口点为 yt-dlp
# Step 7: Set the default entrypoint to yt-dlp
# 运行容器时，命令会传递给 yt-dlp
# When running the container, commands are passed to yt-dlp
ENTRYPOINT ["yt-dlp"]

# 步骤 8: 设置默认命令 (可选)
# Step 8: Set the default command (optional)
# 如果运行容器时不提供任何参数，则显示帮助信息
# If no arguments are provided when running the container, display help information
CMD ["--help"]
